package cn.fz.luck.saas.service.serviceImpl;

import cn.fz.luck.saas.mapper.SysRoleMapper;
import cn.fz.luck.saas.mapper.SysRoleUserMapper;
import cn.fz.luck.saas.model.SysRole;
import cn.fz.luck.saas.model.SysRoleUser;
import cn.fz.luck.saas.service.SysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author zhuangqi
 * @date 2017/7/6.
 */
@Service
public class SysRoleServiceImpl implements SysRoleService{

    @Autowired
    private SysRoleUserMapper sysRoleUserMapper;

    @Autowired
    private SysRoleMapper sysRoleMapper;

    @Override
    public List<SysRole> listByUserId(String userId) {
        SysRoleUser sysRoleUser = new SysRoleUser();
        sysRoleUser.setUserId(userId);
        List<SysRoleUser> sysRoleUsers = sysRoleUserMapper.select(sysRoleUser);
        String roleIds = sysRoleUsers.stream().map(SysRoleUser::getRoleId).collect(Collectors.joining(","));
        return sysRoleMapper.selectByIds(roleIds);
    }
}
